package jbstoremgmt.service;

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import jbstoremgmt.service.BPDetailsBean;;

public class BPValidator implements Validator {

	public boolean supports(Class clazz)	
	{
		return clazz.equals(BPDetailsBean.class);
	}

	public void validate(Object obj, Errors errors)
	{
		BPDetailsBean lBean = (BPDetailsBean) obj;
		if (lBean == null)
		{
			errors.rejectValue("usrid", "error.login.not-specified", null,"Value required.");
		} 
		else 
		{
			//TODO ID should be generatad automatically at a later stage.we will remove the validation later.
		
			if(Integer.toString(lBean.getBp_id())== null)
			{
				errors.rejectValue("errors", "error.fnameblank","User id should be numeric value");	
			}
				
			if(lBean.getBp_fname()== null || lBean.getBp_fname().trim().length() <= 0) {
				//System.out.println("user id null value");
				errors.rejectValue("bp_fname", "error.fnameblank","First Name Required.");
			}
			if (lBean.getBp_lname()== null || lBean.getBp_lname().trim().length() <= 0)
			{
				errors.rejectValue("bp_lname", "error.lnameblank","Last Name Required.");
			}
		}
	}
}